#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include <iostream>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <sensor_msgs/msg/image.hpp>
#include "std_msgs/msg/u_int32.hpp"
#include <cv_bridge/cv_bridge.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include "opencv2/imgproc.hpp"
#include "opencv2/calib3d.hpp"
#include <opencv2/highgui.hpp>

using std::placeholders::_1;
using std::placeholders::_2;

class my_subscriber : public rclcpp::Node
{
public:
    my_subscriber(std::string name): Node(name)
    {
        sub_image = this->create_subscription<sensor_msgs::msg::Image>("image_cxk", 10, std::bind(&my_subscriber::topic_callback_image, this, _1));

        pub_medal_bonus = this->create_publisher<std_msgs::msg::UInt32>("organizer", 10);
    }

private:
    rclcpp::Publisher<std_msgs::msg::UInt32>::SharedPtr pub_medal_bonus;

    rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr sub_image;

    void topic_callback_image(const sensor_msgs::msg::Image::SharedPtr msg)
    {
        cv_bridge::CvImagePtr image_ptr;
        image_ptr = cv_bridge::toCvCopy(msg, "bgr8");
        cv::Mat img_ = image_ptr->image;

        std_msgs::msg::UInt32 bonus;
        bonus.data = 50;
        pub_medal_bonus->publish(bonus);

        RCLCPP_INFO(this->get_logger(), "receive the photo of cxk, give he %d dollar as bonus", bonus.data);
    }
};

int main(int argc, char *argv[])
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<my_subscriber>("one_subscriber");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
